from django.db import models

from utils.BaseModel import BaseModel


# Create your models here.
class Category(BaseModel):
    name = models.CharField(max_length=50)
    parent=models.ForeignKey("self",on_delete=models.CASCADE,null=True,blank=True,related_name="children")
    ishome=models.BooleanField(default=False)
    class Meta:
        db_table = "category"
    def __str__(self):
        return self.name
class Teacher(BaseModel):
    name = models.CharField(max_length=50)
    job=models.CharField(max_length=50)
    headimg=models.CharField(max_length=200)
    intro=models.TextField()
    class Meta:
        db_table = "teacher"
    def __str__(self):
        return self.name
class Course(BaseModel):
    cname=models.CharField(max_length=50)
    price=models.DecimalField(max_digits=8,decimal_places=2)
    discount=models.DecimalField(max_digits=8,decimal_places=2)
    level=models.IntegerField(default=0,choices=((0,"初级"),(1,"中级"),(2,"高级")))
    students=models.IntegerField(default=0)
    cover=models.CharField(max_length=200)
    vedio=models.CharField(max_length=200)
    teacher=models.ForeignKey('Teacher',on_delete=models.CASCADE)
    category=models.ForeignKey('Category',on_delete=models.CASCADE)
    score=models.DecimalField(max_digits=3,decimal_places=1,default=10)
    introduction=models.TextField()
    class Meta:
        db_table = "course"
    def __str__(self):
        return self.cname